home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / merge.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  4.3 KB  |  136 lines  |  [TEXT/ttxt]

  1. #
  2. # test of MERGE TABLES
  3. #
  4.  
  5. drop table if exists t1,t2,t3;
  6. create table t1 (a int not null primary key auto_increment, message char(20));
  7. create table t2 (a int not null primary key auto_increment, message char(20));
  8. INSERT INTO t1 (message) VALUES ("Testing"),("table"),("t1");
  9. INSERT INTO t2 (message) VALUES ("Testing"),("table"),("t2");
  10. create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(t1,t2);
  11. select * from t3;
  12. select * from t3 order by a desc;
  13. drop table t3;
  14. insert into t1 select NULL,message from t2;
  15. insert into t2 select NULL,message from t1;
  16. insert into t1 select NULL,message from t2;
  17. insert into t2 select NULL,message from t1;
  18. insert into t1 select NULL,message from t2;
  19. insert into t2 select NULL,message from t1;
  20. insert into t1 select NULL,message from t2;
  21. insert into t2 select NULL,message from t1;
  22. insert into t1 select NULL,message from t2;
  23. insert into t2 select NULL,message from t1;
  24. insert into t1 select NULL,message from t2;
  25. create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(t1,t2);
  26. explain select * from t3 where a < 10;
  27. explain select * from t3 where a > 10 and a < 20;
  28. select * from t3 where a = 10;
  29. select * from t3 where a < 10;
  30. select * from t3 where a > 10 and a < 20;
  31. explain select a from t3 order by a desc limit 10;
  32. select a from t3 order by a desc limit 10;
  33. select a from t3 order by a desc limit 300,10;
  34. show create table t3;
  35.  
  36. # The following should give errors
  37. create table t4 (a int not null, b char(10), key(a)) type=MERGE UNION=(t1,t2);
  38. --error 1016
  39. select * from t4;
  40. --error 1212
  41. create table t5 (a int not null, b char(10), key(a)) type=MERGE UNION=(test.t1,test_2.t2);
  42.  
  43. # Because of windows, it's important that we drop the merge tables first!
  44. drop table if exists t5,t4,t3,t1,t2;
  45.  
  46. create table t1 (c char(10)) type=myisam;
  47. create table t2 (c char(10)) type=myisam;
  48. create table t3 (c char(10)) union=(t1,t2) type=merge;
  49. insert into t1 (c) values ('test1');
  50. insert into t1 (c) values ('test1');
  51. insert into t1 (c) values ('test1');
  52. insert into t2 (c) values ('test2');
  53. insert into t2 (c) values ('test2');
  54. insert into t2 (c) values ('test2');
  55. select * from t3;
  56. select * from t3;
  57. delete from t3 where 1=1;
  58. select * from t3;
  59. select * from t1;
  60. drop table t3,t2,t1;
  61.  
  62. #
  63. # Test 2
  64. #
  65.  
  66. CREATE TABLE t1 (incr int not null, othr int not null, primary key(incr));
  67. CREATE TABLE t2 (incr int not null, othr int not null, primary key(incr));
  68. CREATE TABLE t3 (incr int not null, othr int not null, primary key(incr))
  69. TYPE=MERGE UNION=(t1,t2);
  70.  
  71. SELECT * from t3;
  72.  
  73. INSERT INTO t1 VALUES ( 1,10),( 3,53),( 5,21),( 7,12),( 9,17);
  74. INSERT INTO t2 VALUES ( 2,24),( 4,33),( 6,41),( 8,26),( 0,32);
  75. INSERT INTO t1 VALUES (11,20),(13,43),(15,11),(17,22),(19,37);
  76. INSERT INTO t2 VALUES (12,25),(14,31),(16,42),(18,27),(10,30);
  77.  
  78. SELECT * from t3 where incr in (1,2,3,4) order by othr;
  79. alter table t3 UNION=(t1);
  80. select count(*) from t3;
  81. alter table t3 UNION=(t1,t2);
  82. select count(*) from t3;
  83. alter table t3 TYPE=MYISAM;
  84. select count(*) from t3;
  85.  
  86. # Test that ALTER TABLE rembers the old UNION
  87.  
  88. drop table t3;
  89. CREATE TABLE t3 (incr int not null, othr int not null, primary key(incr))
  90. TYPE=MERGE UNION=(t1,t2);
  91. show create table t3;
  92. alter table t3 drop primary key;
  93. show create table t3;
  94.  
  95. drop table t3,t2,t1;
  96.  
  97. #
  98. # Test table without unions
  99. #
  100. create table t1 (a int not null) type=merge;
  101. select * from t1;
  102. drop table t1;
  103.  
  104. #
  105. # Bug found by Monty.
  106. #
  107.  
  108. drop table if exists t3, t2, t1;
  109. create table t1 (a int not null, b int not null, key(a,b));
  110. create table t2 (a int not null, b int not null, key(a,b));
  111. create table t3 (a int not null, b int not null, key(a,b)) TYPE=MERGE UNION=(t1,t2);
  112. insert into t1 values (1,2),(2,1),(0,0),(4,4),(5,5),(6,6);
  113. insert into t2 values (1,1),(2,2),(0,0),(4,4),(5,5),(6,6);
  114. flush tables;
  115. select * from t3 where a=1 order by b limit 2;
  116. drop table t3,t1,t2;
  117.  
  118. #
  119. # temporary merge tables
  120. #
  121. drop table if exists t1, t2, t3, t4, t5, t6;
  122. create table t1 (a int not null);
  123. create table t2 (a int not null);
  124. insert into t1 values (1);
  125. insert into t2 values (2);
  126. create temporary table t3 (a int not null) TYPE=MERGE UNION=(t1,t2);
  127. select * from t3;
  128. create temporary table t4 (a int not null);
  129. create temporary table t5 (a int not null);
  130. insert into t4 values (1);
  131. insert into t5 values (2);
  132. create temporary table t6 (a int not null) TYPE=MERGE UNION=(t4,t5);
  133. select * from t6;
  134. drop table if exists t1, t2, t3, t4, t5, t6;
  135.  
  136.